package com.bdqn.t330.ch07.service;

import com.bdqn.t330.ch07.dao.SysUserMapper;
import com.bdqn.t330.ch07.entity.SysUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImp implements UserService {

    @Resource
    SysUserMapper sysUserMapper;


    @Transactional
    @Override
    public boolean adds(List<SysUser> list) {
        boolean bool = true;
        try {
            for (SysUser sysUser : list) {
                if (sysUserMapper.add(sysUser) < 1) {
                    return false;
                }
                //System.out.println(1/0);
                //throw new RuntimeException("运行时异常");
            }
        } catch (Exception e) {
            e.printStackTrace();
            bool = false;
            throw e;
        }
        return bool;
    }

    @Override
    public List<SysUser> getUser(SysUser sysUser) {
        return sysUserMapper.getUserListByPoJo(sysUser);
    }
}
